package com.strive.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.strive.entity.SysRole;
import com.strive.mapper.SysRoleMapper;
import com.strive.service.SysRoleService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author strive.Peng
 * @since 2024-03-14
 */
@Service
public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> implements SysRoleService {

    @Override
    public List<SysRole> listRolesByUserId(Long userId) {
        /**
         * 基本思路
         * 1、根据userID查到关联的roleID
         * 2、根据RoleID查询Role表的角色信息 返回一个角色列表
         */
        List<SysRole> sysRoles = this.list(new QueryWrapper<SysRole>().inSql("id", "select role_id from sys_user_role where user_id = " + userId));
        return sysRoles;
    }
}
